const fs = window.require("fs");

const info = document.getElementById("info");
// console.log(info);
info.innerHTML = `Chrome (v${window.versions.chrome}), Node.js (v${window.versions.node})，electron (v${window.versions.electron})`;

const btn = document.getElementById("btn");
const titleInput = document.getElementById("title");
btn.addEventListener("click", () => {
  const title = titleInput.value;
  window.electron.setTitle(title);
});

const btn2 = document.getElementById("btn2");
const info2 = document.getElementById("info2");
const contentInput = document.getElementById("content");
btn2.addEventListener("click", async () => {
  const content = contentInput.value;
  const len = await window.electron.writeFile(content);
  console.log(len);
  info2.innerHTML = `Fize size: ${len}`;
  // const c = await window.electron.readFile("test.txt", { encoding: "utf-8" });
  const c = await fs.promises.readFile("test.txt", { encoding: "utf-8" });
  info2.innerHTML += `File Content: ${c}`;
});

const counter = document.getElementById('counter')
window.electron.onUpdateCounter((value) => {
  counter.innerText = value.toString()
})
